package
{
	import org.flixel.*;

	public class Enemy extends FlxSprite		
	{
		
		private var xSpeed:int;			
		private var img:Class
		private var shotClock:Number;	
		private var sym:int = 1;

		public function Enemy(Y:int, enemyType:int, back:Boolean)
		{
			img = getEnemyType(enemyType);
			super(30,Y);					
			loadGraphic(img,false);
			if(back) {
				sym = -1;
			}
			xSpeed = 30+FlxU.random()*10*15;
		}
		
		override public function update():void
		{
			velocity.x = xSpeed * sym;
			
			if(sym > 0) {
				if(x > FlxG.width + 30)
				{
					reset(-30,y);
				} 
			}else {
				if(x < -30)
				{
					reset(FlxG.width + 30,y);
				} 		
			}
			
			super.update();
			
			
		}
		
		private function getEnemyType(t:int):Class {
			if(t == 0){
				return Resources.EnemyImg;
			}
			if(t == 1){
				return Resources.Enemy1Img;
			}
			if(t == 2){
				return Resources.Enemy2Img;
			}
			if(t == 3){
				return Resources.Enemy3Img;
			}
			if(t == 4){
				return Resources.Enemy4Img;
			}			
			if(t == 5){
				return Resources.Enemy5Img;
			}	
			return Resources.EnemyImg;
			
		}
	
	}
}